package BusinessDelegate;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;



import DTO.ClienteParticularVO;
import DTO.ClienteVO;
import DTO.DireccionVO;
import DTO.SucursalVO;
import Exception.*;
import Interface.TDAManejoDatos;


public class BDCliente 
{
	private static BDCliente instancia;
	private TDAManejoDatos manejoDatos;
	
	private BDCliente() throws URLException, CommunicationException, LookUpException
	{
		try 
		{
			manejoDatos = (TDAManejoDatos)Naming.lookup ("//localhost/GestionLogisticaCentral");
		} catch (MalformedURLException e) {
			throw new URLException();
		} catch (RemoteException e) {
			throw new CommunicationException();
		} catch (NotBoundException e) {
			throw new LookUpException();
		}
	}
	
	public static BDCliente getInstancia() throws URLException, CommunicationException, LookUpException
	{
		if(instancia == null)
		{
			instancia = new BDCliente();
		}
		return instancia;
	}
	
	
	public void agregarClienteParticular(ClienteParticularVO a, DireccionVO dir)
	{
		try 
		{
			manejoDatos.agregarClienteParticular(a , dir);
		} 
		catch (RemoteException e) 
		{
			e.printStackTrace();
		}
	}
	
	public ArrayList<ClienteVO> getClientesVO() throws NoExisteException
	{
		try {
			return manejoDatos.obtengoClientes();
		} catch (RemoteException e) {
			throw new NoExisteException();
		}
	}
	
	public ClienteParticularVO buscarCliente(int dni) throws NoExisteException
	{
		try{
			return manejoDatos.buscaClienteParticular(dni);
		} catch (RemoteException e) {
			throw new NoExisteException();
		}
	}
	
	public ArrayList<SucursalVO> buscarSucursales() throws NoExisteException
	{
		try{
			return manejoDatos.buscarSucursales();
		} catch (RemoteException e) {
			throw new NoExisteException();
		}
	}
	
}

